package com.tushu.dao;

import com.tushu.model.Admin;
import com.tushu.utils.ConnDB;
import com.tushu.utils.DataUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdminDao extends BaseDAO {
    //查询所有
    public List<Admin> selectAdminList() {
        String sql = "select * from tb_admin";
        return super.selectAll(sql, new Object[]{});
    }

    //通过账号查询一个用户
    public Admin selectAdmin(String account) {
        String sql = "select * from tb_admin where account=?";
        return super.select(sql, new Object[]{account});
    }

    @Override
    public Admin rowMapper(ResultSet rs) throws SQLException {
        Admin admin = new Admin();
        admin.setId(rs.getInt("id"));
        admin.setAccount(rs.getString("account"));
        admin.setPassword(rs.getString("password"));
        admin.setName(rs.getString("name"));
        return admin;
    }

    public int getCount(String sql) {
        ResultSet set = null;
        try {
            set = DataUtils.query(sql, null);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        int Count = 0;
        try {
            while (set.next()) {
                Count = set.getInt(1);

            }
            return Count;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
